package visual;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import basicas.PessoaFisica;

import fachada.Fachada;

import modelo.ModeloPessoaFisica;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;

public class RemoverPessoaFisica extends JPanel {

	private static final long serialVersionUID = 1L;
	private ModeloPessoaFisica modelo = new ModeloPessoaFisica();  //  @jve:decl-index=0:visual-constraint="1013,3"
	private JButton btnLocalizar = null;
	private JTextField txtLocalizar = null;
	private JScrollPane jScrollPane = null;
	private JTable TabelaLocalizar = null;
	private JPanel jPanelLocaliza = null;
	private JLabel lblID = null;
	private JTextField txtID = null;
	private JButton btnRemover = null;
	private JPanel jPanelDadosCliente = null;
	private JLabel lblTitulo = null;
	/**
	 * This is the default constructor
	 */
	public RemoverPessoaFisica() {
		super();
		initialize();
		txtID.setEditable(false);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		lblTitulo = new JLabel();
		lblTitulo.setBounds(new Rectangle(204, 38, 188, 15));
		lblTitulo.setFont(new Font("Dialog", Font.BOLD, 18));
		lblTitulo.setText("Remover Cliente");
		lblID = new JLabel();
		lblID.setText("ID do cliente:");
		lblID.setBounds(new Rectangle(175, 31, 105, 15));
		this.setSize(623, 523);
		this.setLayout(null);
		this.add(getJScrollPane(), null);
		this.add(getJPanelLocaliza(), null);
		this.add(getJPanelDadosCliente(), null);
		this.add(lblTitulo, null);
	}

	/**
	 * This method initializes btnLocalizar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnLocalizar() {
		if (btnLocalizar == null) {
			btnLocalizar = new JButton();
			btnLocalizar.setIcon(new ImageIcon(getClass().getResource("/Icones/localizar/Search-icon.png")));
			btnLocalizar.setBounds(new Rectangle(412, 29, 130, 25));
			btnLocalizar.setText("Localizar");
			btnLocalizar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Fachada F = new Fachada();
					Vector vetor = null;

					try {
						vetor = F.consultaFisicaFiltrada(txtLocalizar.getText());
					} catch (Exception e1) {

					}
					modelo.removeAll();
					Iterator it = vetor.iterator();

					while (it.hasNext()) {
						PessoaFisica procura = (PessoaFisica) it.next();
						modelo.adicionar(procura);
					}
					txtID.setEditable(true);
				}

			});
		}
		return btnLocalizar;
	}

	/**
	 * This method initializes txtLocalizar	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtLocalizar() {
		if (txtLocalizar == null) {
			txtLocalizar = new JTextField();
			txtLocalizar.setBounds(new Rectangle(12, 32, 391, 20));
			txtLocalizar.setToolTipText("Digite aqui o nome para consulta filtrada");
		}
		return txtLocalizar;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(20, 283, 567, 150));
			jScrollPane.setViewportView(getTabelaLocalizar());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes TabelaLocalizar	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getTabelaLocalizar() {
		if (TabelaLocalizar == null) {
			TabelaLocalizar = new JTable(modelo);
		}
		return TabelaLocalizar;
	}

	/**
	 * This method initializes jPanelLocaliza	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelLocaliza() {
		if (jPanelLocaliza == null) {
			jPanelLocaliza = new JPanel();
			jPanelLocaliza.setLayout(null);
			jPanelLocaliza.setBounds(new Rectangle(28, 105, 561, 75));
			jPanelLocaliza.setBorder(BorderFactory.createCompoundBorder(
					BorderFactory.createTitledBorder("Localizar Cliente: "),
					BorderFactory.createEmptyBorder(5, 5, 5, 5)));
			jPanelLocaliza.add(getBtnLocalizar(), null);
			jPanelLocaliza.add(getTxtLocalizar(), null);
		}
		return jPanelLocaliza;
	}

	/**
	 * This method initializes txtID	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtID() {
		if (txtID == null) {
			txtID = new JTextField();
			txtID.setBounds(new Rectangle(292, 30, 28, 19));
			txtID.setToolTipText("Digite o ID do Cliente");
		}
		return txtID;
	}

	/**
	 * This method initializes btnRemover	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnRemover() {
		if (btnRemover == null) {
			btnRemover = new JButton();
			btnRemover.setText("Remover");
			btnRemover.setBounds(new Rectangle(431, 25, 100, 24));
			btnRemover.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Fachada F = new Fachada();
					
					try {
						
						F.removerPessoaFisica(Integer.parseInt(txtID.getText()));
						JOptionPane.showMessageDialog(null, "Usuário Removido com sucesso !!!",
								"ConfifureKar - Exclusão de Cliente",
								JOptionPane.INFORMATION_MESSAGE);
						
					} catch (NumberFormatException e1) {
						e1.printStackTrace();
					} catch (ClassNotFoundException e1) {

						e1.printStackTrace();
					} catch (SQLException e1) {

						e1.printStackTrace();
					}
				}
			});
		}
		return btnRemover;
	}

	/**
	 * This method initializes jPanelDadosCliente	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelDadosCliente() {
		if (jPanelDadosCliente == null) {
			jPanelDadosCliente = new JPanel();
			jPanelDadosCliente.setLayout(null);
			jPanelDadosCliente.setBounds(new Rectangle(26, 191, 563, 66));
			jPanelDadosCliente.setBorder(BorderFactory.createCompoundBorder(
					BorderFactory.createTitledBorder("dado do Cliente: "),
					BorderFactory.createEmptyBorder(5, 5, 5, 5)));
			jPanelDadosCliente.add(getTxtID(), null);
			jPanelDadosCliente.add(lblID, null);
			jPanelDadosCliente.add(getBtnRemover(), null);
		}
		return jPanelDadosCliente;
	}

}  //  @jve:decl-index=0:visual-constraint="10,-52"
